<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>P134 6.2.6 【案例】限时秒杀</title>
</head>

<body>
    <div class="box">
        <div id="d"></div>
        <div id="h"></div>
        <div id="m"></div>
        <div id="s"></div>
        <script>
            var endTime = new Date('2017-11-10 18:51:00'), endSeconds = endTime.getTime();
            var d = h = m = s = 0;
            var id = setInterval(seckill, 1000);
            function seckill() {
                var nowTime = new Date();
                var remaining = parseInt((endSeconds - nowTime.getTime()) / 1000);
                if (remaining > 0) {
                    d = parentInt(remaining / 86400);
                    h = parentInt((remaining / 3600) % 24);
                    m = parentInt((remaining / 60) % 60);
                    s = parentInt(remaining % 60);
                    d = d < 10 ? '0' + d : d;
                    h = h < 10 ? '0' + h : h;
                    m = m < 10 ? '0' + m : m;
                    s = s < 10 ? '0' + s : s;
                } else {
                    clearInterval(id);
                    d = h = m = s = '00';
                }
                document.getElementById('d').innerHTML = d + '天';
                document.getElementById('h').innerHTML = h + '时';
                document.getElementById('m').innerHTML = m + '分';
                document.getElementById('s').innerHTML = s + '秒';
            }
        </script>
        <a href="../首页/page06.html">
            <h2>返回上一页面</h2>
        </a>
</body>

</html>